package com.example.meterialproject.activitys.view_life

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.example.meterialproject.R

/**
 *
 * @ClassName: TestViewLifeSecondActivity
 * @Author: android 超级兵
 * @CreateDate: 4/15/22$ 7:24 PM$
 * TODO 测试View生命周期
 */
//class TestViewLifeSecondActivity :BaseActivity<ActivityTestViewLifeSecondBinding>(){
class TestViewLifeSecondActivity : AppCompatActivity() {

    companion object {
        private const val TAG = "szj_TestActivity"
    }

    /*
     * 作者:android 超级兵
     * 创建时间: 4/19/22 4:33 PM
     * TODO 点击事件
     */
    fun onLifeViewClick(v: View) {
        val temp = randomInt(20, -20)
        v.x += temp
        v.y += temp
        Log.d("Click", "temp:$temp")

//        v.layoutParams.width = v.width + temp
//        v.layoutParams.height = v.height + temp

        // 只会调用 onDraw 方法
        // v.invalidate()
        // 会重新测量绘制 onMeasure -> onSizeChanged() -> onLayout() -> onDraw()
        v.requestLayout()
    }

    private fun randomInt(m: Int, n: Int) = let {
        (Math.random() * (n - m + 1) + m).toInt()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e(TAG, "activity onCreate start")
        setContentView(R.layout.activity_test_view_life_second)
        Log.e(TAG, "activity onCreate end")
    }

    override fun onStart() {
        super.onStart()
        Log.e(TAG, "activity onStart")
    }

    override fun onPause() {
        super.onPause()
        Log.e(TAG, "activity onPause")
    }

    override fun onResume() {
        super.onResume()
        Log.e(TAG, "activity onResume")
    }

    override fun onRestart() {
        super.onRestart()
        Log.e(TAG, "activity onRestart")
    }

    override fun onStop() {
        super.onStop()
        Log.e(TAG, "activity onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(TAG, "activity onDestroy")
    }
}